﻿namespace Harness.Commands
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    internal class GoCommand : ICommand
    {
        #region Constants

        private const int UrlArgIndex = 0;

        #endregion

        #region Public Methods

        public void SyntaxCheck(IHarness harness, IEnumerable<object> args)
        {
            if (null == args.ElementAtOrDefault(UrlArgIndex))
            {
                throw new ArgumentNullException((UrlArgIndex + 1).ToString() + ":Url");
            }
        }

        public dynamic Execute(IHarness harness, IEnumerable<object> args)
        {
            string url = (args.ElementAtOrDefault(UrlArgIndex) ?? string.Empty).ToString();
            url = harness.GetAbsoluteUrl(url);
            IE.Navigate(url);

            return null;
        }

        #endregion
    }
}
